//
//  CS_Page_TextFieldView.m
//  Pods
//
//  Created by 网新中研 on 2017/5/16.
//
//

#import "CS_Page_TextFieldView.h"
#import "Common.h"
#import "JVFloatLabeledTextField.h"

#define EMPTY_TEXT_FIELD @"EMPTY_TEXT_FIELD"

@interface CS_Page_TextFieldView()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *textField;

@property (nonatomic, strong) UIView *seperatorLine;

@property (nonatomic, strong) UIImageView *iconImageView;

@property (nonatomic, strong) JVFloatLabeledTextField *floatLabledTextField;

@property (nonatomic, assign) BOOL isPassword;

@property (nonatomic, strong) UIView *focusLine;

@property (nonatomic, strong) UIImageView *validateResultImageView;

@property (nonatomic, strong) UIButton *selectButton;


/**
 * 加入正在执行震动动画
 */
@property (nonatomic, assign) BOOL isShakingAnimate;



/*********************************************************************
 *
 *  对于点击选择型输入，采用UILabel进行显示并支持多行的显示
 *
 *********************************************************************/
@property (nonatomic, strong) UILabel *clickTitleLabel;
@property (nonatomic, strong) CS_Page_TextView *clickValue_CS_Page_TextView;


@end

@implementation CS_Page_TextFieldView

/**
 * 图标
 */
static NSMutableDictionary *_iconDic;


/**
 * 加载textfield
 */
+(void)loadImageWithType:(CSTextFieldType)key value:(UIImage *)image{
    if(_iconDic == nil){
        _iconDic = [NSMutableDictionary new];
    }
    
    if (image == nil) {
        return;
    }
    
    [_iconDic setObject:image forKey:@(key)];
}


+(instancetype)textFiledWithPlaceHolder:(NSString *)placeHolder{
    CS_Page_TextFieldView *textField = [CS_Page_TextFieldView new];
    textField.placeHolder = placeHolder;
    textField.keyboardType = UIKeyboardTypeDefault;
    return textField;
}

+(instancetype)textFiledWithPlaceHolder:(NSString *)placeHolder keyboardType:(UIKeyboardType)keyboardType{
    CS_Page_TextFieldView *textField = [CS_Page_TextFieldView new];
    textField.placeHolder = placeHolder;
    textField.keyboardType = keyboardType;
    
    return textField;
}

+(instancetype)textFiledWithPlaceHolder:(NSString *)placeHolder keyboardType:(UIKeyboardType)keyboardType isPassword:(BOOL)isPassword{
    CS_Page_TextFieldView *textField = [CS_Page_TextFieldView new];
    textField.placeHolder = placeHolder;
    textField.keyboardType = keyboardType;
    textField.isPassword = isPassword;
    return textField;
}

+(instancetype)textFiledWithPlaceHolder:(NSString *)placeHolder keyboardType:(UIKeyboardType)keyboardType data:(NSString *)data{
    CS_Page_TextFieldView *textField = [CS_Page_TextFieldView new];
    textField.placeHolder = placeHolder;
    textField.keyboardType = keyboardType;
    textField.value = data;
    
    return textField;
}

#define IMAGE_HEIGHT 25.0
#define IMGAE_MARGIN 4.0
#define ICON_HEIGHT 40.0
#define FLOAT_TEXT_HEIGHT 50.0

-(CGFloat)layoutView:(UIView *)superView primaryY:(CGFloat)primaryY{
    
    [superView addSubview:self];
    
    CGFloat txtHeight = FLOAT_TEXT_HEIGHT;
    
    CGFloat needHeight = 0.0;
    
    //是否有对应的图标
    UIImage *iconImage = [_iconDic objectForKey:@(self.textFieldType)];
    
    iconImage = nil;
    
    if (iconImage) {
        
        self.iconImageView = [[UIImageView alloc]initWithImage:iconImage];
        self.iconImageView.frame = CGRectMake(CELL_EDIT_RIGHT_MARGIN - 5, txtHeight + CELL_CONTENT_MARGIN_HEIGHT * 2 - 10 - IMAGE_HEIGHT , IMAGE_HEIGHT, IMAGE_HEIGHT);
        [self addSubview:self.iconImageView];
        
        self.floatLabledTextField.secureTextEntry = self.isPassword;
        
        self.validateResultImageView.frame = CGRectMake(kWindowW - ICON_HEIGHT - CELL_RIGHT_MARGIN, txtHeight + CELL_CONTENT_MARGIN_HEIGHT * 2 - 5 - ICON_HEIGHT - 3, ICON_HEIGHT, ICON_HEIGHT);
        
        self.floatLabledTextField.frame = CGRectMake(CELL_EDIT_RIGHT_MARGIN + IMAGE_HEIGHT + IMGAE_MARGIN, CELL_CONTENT_MARGIN_HEIGHT + 6, kWindowW - 2 * CELL_EDIT_RIGHT_MARGIN - IMGAE_MARGIN - IMAGE_HEIGHT - 20, txtHeight);
        
        self.seperatorLine.frame = CGRectMake(CELL_EDIT_RIGHT_MARGIN + IMAGE_HEIGHT + IMGAE_MARGIN, txtHeight + CELL_CONTENT_MARGIN_HEIGHT * 2 - 5, kWindowW - 2 * CELL_EDIT_RIGHT_MARGIN - IMGAE_MARGIN - IMAGE_HEIGHT, 0.6);
        self.seperatorLine.layer.opacity = 0.3;
        [self addSubview:self.floatLabledTextField];
        [self addSubview:self.seperatorLine];
        
        needHeight = txtHeight + CELL_CONTENT_MARGIN_HEIGHT * 2 + 10;
        
        self.frame = CGRectMake(0, primaryY, kWindowW, needHeight);
        
    } if ([self isClickEditType]) {
        
        //显示标题
        self.clickTitleLabel.frame = CGRectMake(self.leftMargin, CELL_CONTENT_MARGIN_HEIGHT, kWindowW - self.leftMargin - self.rightMargin, 20.0);
        [self addSubview:self.clickTitleLabel];
        needHeight += CELL_CONTENT_MARGIN_HEIGHT + 20.0 + 7;
        
        //显示值
        self.clickValue_CS_Page_TextView.rightMargin = ICON_HEIGHT/2.0 + self.rightMargin;
        needHeight = [self.clickValue_CS_Page_TextView layoutView:self primaryY:needHeight];
        
        //添加右箭头
        self.downArrowImageView.frame = CGRectMake(kWindowW - ICON_HEIGHT/2.0 - self.rightMargin, (needHeight - ICON_HEIGHT)/2.0 + CELL_CONTENT_MARGIN_HEIGHT, ICON_HEIGHT / 2.0 - 2, ICON_HEIGHT / 2.0 - 2);
        [self addSubview:self.downArrowImageView];
        
        self.seperatorLine.frame = CGRectMake(self.leftMargin, needHeight, kWindowW - self.leftMargin - self.rightMargin, 0.6);
        [self addSubview:self.seperatorLine];
        
        needHeight += 7;
        
        self.frame = CGRectMake(0, primaryY, kWindowW, needHeight);
        self.selectButton.frame = CGRectMake(0, 0, kWindowW, self.frame.size.height - 7);
        [self addSubview:self.selectButton];
        
    } else {
        
        //是否加密
        self.floatLabledTextField.secureTextEntry = self.isPassword;
        
        self.floatLabledTextField.frame = CGRectMake(self.leftMargin, CELL_CONTENT_MARGIN_HEIGHT + 6, kWindowW - self.leftMargin - self.rightMargin, txtHeight);
        
        if (![self isNullOrEmpty:self.floatLabledTextField.text]) {
            
            self.floatLabledTextField.frame = CGRectMake(self.leftMargin, CELL_CONTENT_MARGIN_HEIGHT + 6, kWindowW - self.leftMargin - self.rightMargin - IMGAE_MARGIN - IMAGE_HEIGHT, txtHeight);
            
            self.validateResultImageView.frame = CGRectMake(kWindowW - ICON_HEIGHT - self.rightMargin, (self.validateResultImageView.frame.origin.y == 0 ? (35.0 + CELL_CONTENT_MARGIN_HEIGHT * 2 - 5 - ICON_HEIGHT - 3 - 5) : self.validateResultImageView.frame.origin.y), ICON_HEIGHT, ICON_HEIGHT);
            
        }
        
        self.seperatorLine.frame = CGRectMake(self.leftMargin, txtHeight + CELL_CONTENT_MARGIN_HEIGHT * 2 - 4, kWindowW - self.leftMargin - self.rightMargin, 0.6);
        self.seperatorLine.layer.opacity = 0.3;
        [self addSubview:self.floatLabledTextField];
        [self addSubview:self.seperatorLine];
        
        needHeight = txtHeight + CELL_CONTENT_MARGIN_HEIGHT * 2 + 7;
        
        self.frame = CGRectMake(0, primaryY, kWindowW, needHeight);
        
    }
    
//    if ([self isClickEditType]) {
//
//        self.downArrowImageView.frame = CGRectMake(kWindowW - ICON_HEIGHT/2.0 - 5 - self.rightMargin, txtHeight + CELL_CONTENT_MARGIN_HEIGHT * 2 - 12 - IMAGE_HEIGHT, ICON_HEIGHT / 2.0 - 2, ICON_HEIGHT / 2.0 - 2);
//
//        [self addSubview:self.downArrowImageView];
//
//        self.selectButton.frame = CGRectMake(0, 0, kWindowW, self.frame.size.width);
//        [self addSubview:self.selectButton];
//
//    }
    
    if (self.isForbiddenEdit) {
        UIView *forbiddenView = [[UIView alloc] init];
        forbiddenView.backgroundColor = [UIColor colorFromHexCode:@"f0f0f0"];
        forbiddenView.frame = CGRectMake(0, -14, kWindowW, self.frame.size.height);
        //        forbiddenView.layer.opacity = 0.5;
        [self insertSubview:forbiddenView atIndex:0];
        self.floatLabledTextField.textColor = COLOR_TEXT_3;
        //        [self.seperatorLine removeFromSuperview];
        self.seperatorLine.frame = CGRectMake(0, self.seperatorLine.frame.origin.y, kWindowW, 0.7);
        UIView *coverView = [UIView new];
        coverView.frame = forbiddenView.frame;
        [self addSubview:coverView];
    }
    
    return primaryY + needHeight;
}

-(void)setTextFieldType:(CSTextFieldType)textFieldType{
    
    NSString *currentValue = @"";
    
    //由于点击类型和输入类型保存数据的地方不同，先把两处的数据取出来并进行还原处理
    if ([self isClickEditType]) {
        currentValue = self.clickValue_CS_Page_TextView.value;
    }else{
        currentValue = self.floatLabledTextField.text;
    }
    if (![self isNullOrEmpty:currentValue] && [currentValue isEqualToString:[self getFormatPlacePlaceHolder]]) {
        currentValue = @"";
    }
    
    //修改当前输入框的类型
    _textFieldType = textFieldType;
    
    //修改类型后，对输入框的值重新进行处理
    if ([self isClickEditType]) {
        
        if ([self isNullOrEmpty:currentValue]) {//没有值得处理
            currentValue = [self getFormatPlacePlaceHolder];
            [self.clickValue_CS_Page_TextView refreshTextColor:COLOR_TEXT_3];
            [self.clickValue_CS_Page_TextView refreshFont:[UIFont systemFontOfSize:FONT_SIZE_1]];
        }else{//有值得处理
            [self.clickValue_CS_Page_TextView refreshFont:[UIFont boldSystemFontOfSize:FONT_SIZE_1]];
            [self.clickValue_CS_Page_TextView refreshTextColor:COLOR_TEXT_1];
        }
        
        self.clickValue_CS_Page_TextView.value = currentValue;
    }else{
        self.floatLabledTextField.text = currentValue;
        self.floatLabledTextField.textColor = COLOR_TEXT_1;
    }
    
//    if ([self.floatLabledTextField.text isEqualToString:[self getFormatPlacePlaceHolder]]
//        ||[self isNullOrEmpty:self.floatLabledTextField.text]) {
//        _textFieldType = textFieldType;
//        self.floatLabledTextField.text = [self getFormatPlacePlaceHolder];
//        self.floatLabledTextField.textColor = COLOR_TEXT_3;
//    }else{
//        _textFieldType = textFieldType;
//    }
    
}

-(NSInteger)viewType{
    return CSViewType_PageTextFieldView;
}

-(void)setIsForbiddenEdit:(BOOL)isForbiddenEdit{
    _isForbiddenEdit = isForbiddenEdit;
    
    if (_isForbiddenEdit) {
        self.floatLabledTextField.textColor = COLOR_TEXT_3;
        self.validateResultImageView.layer.opacity = 0.0;
    }
    
}

/**
 * 是否是选中才能编辑的类型
 */
-(BOOL)isClickEditType{
    
    if (self.textFieldType == CSTextFieldType_DateTime
        || self.textFieldType == CSTextFieldType_Person
        || self.textFieldType == CSTextFieldType_EnterpriseType
        || self.textFieldType == CSTextFieldType_Click
        || self.isDownArrowRequired) {
        
        return YES;
        
    }
    
    return NO;
}

-(JVFloatLabeledTextField *)floatLabledTextField{
    if (_floatLabledTextField == nil) {
        _floatLabledTextField = [[JVFloatLabeledTextField alloc] initWithFrame:CGRectZero];
        _floatLabledTextField.font = [UIFont systemFontOfSize:FONT_SIZE_REM];
        _floatLabledTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:NSLocalizedString(self.placeHolder, @"")
                                                                                      attributes:@{NSForegroundColorAttributeName: COLOR_TEXT_2, NSFontAttributeName:[UIFont systemFontOfSize:FONT_SIZE_REM]}];
        _floatLabledTextField.floatingLabelFont = [UIFont systemFontOfSize:FONT_SIZE_1];
//        _floatLabledTextField.floatingLabelTextColor = [UIColor colorFromHexCode:@"838082"];
        _floatLabledTextField.floatingLabelTextColor = COLOR_TEXT_2;
        _floatLabledTextField.floatingLabelActiveTextColor =  COLOR_THEME;
        _floatLabledTextField.textColor = COLOR_TEXT_3;
        _floatLabledTextField.keyboardType = _keyboardType;
        _floatLabledTextField.returnKeyType = UIReturnKeyDone;
        _floatLabledTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        _floatLabledTextField.alwaysShowFloatingLabel = YES;
        _floatLabledTextField.delegate = self;
//        _floatLabledTextField.keepBaseline = YES;
        _floatLabledTextField.placeholderColor = [UIColor clearColor];
//        _floatLabledTextField.placeholder = self.placeHolder;
        
//        _floatLabledTextField.placeholderColor = 
        
        self.titleLabel.layer.borderColor = [UIColor colorFromHexCode:@"838082"].CGColor;
        self.titleLabel.layer.borderWidth = 0.8;
        self.titleLabel.layer.cornerRadius = 3;
        self.titleLabel.layer.masksToBounds = YES;

        _floatLabledTextField.floatingLabelYPadding = -15.0 + 13;
        _floatLabledTextField.placeholderYPadding = -17.0 + 15;
    }
    return _floatLabledTextField;
}

#pragma mark --- UITextFieldDelegate

//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // return NO to disallow editing.
- (void)textFieldDidBeginEditing:(UITextField *)textField{             // became first responder
    
    if ([textField.text isEqualToString:[self getFormatPlacePlaceHolder]]) {
        textField.text = @"";
    }
    
    self.floatLabledTextField.font = [UIFont boldSystemFontOfSize:FONT_SIZE_1];
    
    if (self.iconImageView) {
        self.floatLabledTextField.frame = CGRectMake(self.floatLabledTextField.frame.origin.x, self.floatLabledTextField.frame.origin.y, kWindowW -self.rightMargin - self.floatLabledTextField.frame.origin.x, self.floatLabledTextField.frame.size.height);
    }else{
        self.floatLabledTextField.frame = CGRectMake(self.floatLabledTextField.frame.origin.x, self.floatLabledTextField.frame.origin.y, kWindowW - self.leftMargin - self.rightMargin, self.floatLabledTextField.frame.size.height);
    }
    
    self.floatLabledTextField.textColor = COLOR_TEXT_1;
    [self.validateResultImageView removeFromSuperview];
    [self doFocusAnimation];
}

- (void)textFieldDidEndEditing:(UITextField *)textField{               // may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called
    
    [self showResult:textField isAnimationNeeded:YES];
    return;
    
}

-(void)showResult:(UITextField *)textField isAnimationNeeded:(BOOL)isAnimationNeeded{
    
    if (self.textFieldType == CSTextFieldType_Person
        || self.textFieldType == CSTextFieldType_DateTime) {
        [self addSubview:self.downArrowImageView];
    }
    
    if (self.floatLabledTextField.text != nil
        && ![self.floatLabledTextField.text isEqualToString:@""]) {
        
        
         self.floatLabledTextField.font = [UIFont boldSystemFontOfSize:FONT_SIZE_1];
        self.floatLabledTextField.textColor = [UIColor colorFromHexCode:@"bbb"];
        
        self.floatLabledTextField.frame = CGRectMake(self.floatLabledTextField.frame.origin.x, self.floatLabledTextField.frame.origin.y, kWindowW - self.leftMargin - self.rightMargin - IMGAE_MARGIN - IMAGE_HEIGHT - 20, self.floatLabledTextField.frame.size.height);
        
    }else{
        [self addSubview:self.seperatorLine];
    }
    
    [self doUnfocusAnimation];
    
    if ((self.textFieldType == CSTextFieldType_Phone
         && ![textField.text isVAlidPhoneNumber])
        ||(self.textFieldType == CSTextFieldType_Email)
        && ![textField.text isValidEmail]) {//如果是电话号码类型且电话号码格式错误
        
        if (isAnimationNeeded) {
            [self showError];
        }
        
        [self.validateResultImageView removeFromSuperview];
        self.floatLabledTextField.textColor = [UIColor colorFromHexCode:@"ca4c4f"];
        
    }else{
        
        self.floatLabledTextField.frame = CGRectMake(self.floatLabledTextField.frame.origin.x, CELL_CONTENT_MARGIN_HEIGHT + 6, kWindowW - self.leftMargin - self.rightMargin - IMGAE_MARGIN - IMAGE_HEIGHT, self.floatLabledTextField.frame.size.height);
        
    }
    
    if (self.isForbiddenEdit) {
        self.floatLabledTextField.textColor = COLOR_TEXT_3;
    }
    
    //如果结果为空
    if ([self isNullOrEmpty:self.floatLabledTextField.text]
        ||[self.floatLabledTextField.text isEqualToString:[self getFormatPlacePlaceHolder]]) {
        self.floatLabledTextField.text = [self getFormatPlacePlaceHolder];
        self.floatLabledTextField.textColor = [UIColor colorFromHexCode:@"bbb"];
        self.floatLabledTextField.font = [UIFont systemFontOfSize:FONT_SIZE_1];
    }else{
        self.floatLabledTextField.textColor = COLOR_TEXT_1;
    }
    
    //设置段落属性
    NSDictionary *attributes = @{
                                 NSFontAttributeName:self.floatLabledTextField.font,
                                 NSForegroundColorAttributeName:self.floatLabledTextField.textColor
                                 };
    
    NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:self.floatLabledTextField.text attributes:attributes];
    [CSBaseView colorApplicationColoredString:mutableAttributedString];
    
    self.floatLabledTextField.attributedText = mutableAttributedString;
    
    //值改变处理
    if (self.valueChangedHandler) {
        self.valueChangedHandler(self);
    }
}


-(void)doFocusAnimation{
    [self addSubview:self.focusLine];
    self.focusLine.frame = CGRectMake(self.seperatorLine.frame.origin.x, self.seperatorLine.frame.origin.y, 0, 1);
    WS(weakSelf);
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.focusLine.frame = CGRectMake(weakSelf.seperatorLine.frame.origin.x, weakSelf.seperatorLine.frame.origin.y, weakSelf.seperatorLine.frame.size.width, 1.5);
    }];
}

/**
 * 显示错误
 */
-(void)showError{
    
    if (self.isShakingAnimate) {
        return;
    }
    
    self.isShakingAnimate = YES;
    
    CGRect originRect = self.frame;
    [self shakeAnimate:0 originRect:originRect];
}

-(void)shakeAnimate:(int)shakeTimes originRect:(CGRect)originRect{
    
    CGRect targetRect = originRect;
    CGFloat shakeDeviation = 10.0;
    
    if (shakeTimes % 2 == 0) {
        targetRect = CGRectMake(originRect.origin.x + shakeDeviation, originRect.origin.y, originRect.size.width, originRect.size.height);
    }else{
        targetRect = CGRectMake(originRect.origin.x - shakeDeviation, originRect.origin.y, originRect.size.width, originRect.size.height);
    }
    
    __block int weakShakeTimes = shakeTimes;
    WS(weakSelf);
    
    [UIView animateWithDuration:0.05 animations:^{
        weakSelf.frame = targetRect;
    } completion:^(BOOL finished) {
        weakShakeTimes = weakShakeTimes + 1;
        
        if (weakShakeTimes == 6) {
            weakSelf.frame = originRect;
            weakSelf.isShakingAnimate = NO;
        }else{
            [weakSelf shakeAnimate:weakShakeTimes originRect:originRect];
        }
    }];
    
}

-(void)selectClick{
    if (self.textFieldType == CSTextFieldType_DateTime) {
        
        WS(weakSelf);
        CSDatePickerView *datePickerView = [CSDatePickerView instanceDateTimePickViewWithSaveClickHandler:^(NSString *selectDate) {
            
            weakSelf.value = selectDate;
            
        } cancelClickHandler:^{

        }];

        [datePickerView popShow];
    }else if (self.textFieldType == CSTextFieldType_Person){
        
        if (self.selectHandler) {
            self.selectHandler(self);
        }
    }else {
        if (self.clickHandler) {
            self.clickHandler(self);
        }
        
    }
}

-(void)doUnfocusAnimation{
    [self addSubview:self.focusLine];
    self.focusLine.frame = CGRectMake(self.seperatorLine.frame.origin.x, self.seperatorLine.frame.origin.y, self.seperatorLine.frame.size.width, 1);
    WS(weakSelf);
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.focusLine.frame = CGRectMake(weakSelf.seperatorLine.frame.origin.x + weakSelf.seperatorLine.frame.size.width, weakSelf.seperatorLine.frame.origin.y, 0, 1.5);
    }];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.floatLabledTextField resignFirstResponder];
    return YES;
}

-(UIView *)seperatorLine{
    if (_seperatorLine == nil) {
        _seperatorLine = [UIView new];
        _seperatorLine.backgroundColor = [UIColor colorFromHexCode:@"b6b8bf"];
        _seperatorLine.layer.opacity = 0.2;
        [self drawLineOfDashByCAShapeLayer:_seperatorLine lineLength:10 lineSpacing:10 lineColor:COLOR_TOP_SEPERATOR_LINE lineDirection:YES];
    }
    return _seperatorLine;
}

-(UIView *)focusLine{
    if (_focusLine == nil) {
        _focusLine = [[UIView alloc]init];
        _focusLine.backgroundColor = COLOR_THEME;
    }
    return _focusLine;
}

-(UIImageView *)validateResultImageView{
    if (_validateResultImageView == nil) {
        _validateResultImageView = [UIImageView new];
    }
    return _validateResultImageView;
}

-(NSString *)value{
    
    if ([self isClickEditType]) {
        
        if (_clickValue_CS_Page_TextView == nil
            ||_clickValue_CS_Page_TextView.value == nil
            ||[_clickValue_CS_Page_TextView.value isEqualToString:[self getFormatPlacePlaceHolder]]) {
            return @"";
        }
        
        //如果是个点击类型
        return self.clickValue_CS_Page_TextView.value;
    }
    
    if (_floatLabledTextField == nil
        ||_floatLabledTextField.text == nil
        ||[_floatLabledTextField.text isEqualToString:[self getFormatPlacePlaceHolder]]) {
        return @"";
    }
    
    return _floatLabledTextField.text;
}

-(NSString *)getFormatPlacePlaceHolder{
    
    NSString *formatPlaceHolder = [NSString stringWithFormat:@"请输入%@", self.placeHolder];
    
    if (self.textFieldType == CSTextFieldType_Click
        || self.textFieldType == CSTextFieldType_Person
        ) {
        
        formatPlaceHolder = [NSString stringWithFormat:@"请选择%@", self.placeHolder];
        
    }else if(self.textFieldType == CSTextFieldType_DateTime){
        
        formatPlaceHolder = [NSString stringWithFormat:@"请选择%@", self.placeHolder];
        
    }
    
    if (![self isNullOrEmpty:self.displayPlaceHolder]) {
        formatPlaceHolder = self.displayPlaceHolder;
    }
    
    return formatPlaceHolder;
}

-(void)setValue:(NSString *)value{
    
    NSString *valueString = value;
    if ([self isNullOrEmpty:value]) {
        valueString = [self getFormatPlacePlaceHolder];
    }
    
    if ([self isClickEditType]) {//点击类型
        
        //修改显示的颜色
        if ([valueString isEqualToString:[self getFormatPlacePlaceHolder]]) {
            [self.clickValue_CS_Page_TextView refreshTextColor:[UIColor colorFromHexCode:@"bbb"]];
            [self.clickValue_CS_Page_TextView refreshFont:[UIFont systemFontOfSize:FONT_SIZE_1]];
        }else{
            [self.clickValue_CS_Page_TextView refreshTextColor:COLOR_TEXT_1];
            [self.clickValue_CS_Page_TextView refreshFont:[UIFont boldSystemFontOfSize:FONT_SIZE_1]];
        }
        
        [self.clickValue_CS_Page_TextView refreshContent:valueString];
        
        //刷新界面
        [self refreshSelfAndAdjustContext];
        
    }else{//普通类型
        
        self.floatLabledTextField.text = valueString;
        
        [self.floatLabledTextField layoutSubviews];
        
        [self showResult:_floatLabledTextField isAnimationNeeded:NO];
        
    }
    
    
    
}

-(void)reset{
    _floatLabledTextField.text = @"";
    [self showResult:_floatLabledTextField isAnimationNeeded:NO];
}

-(void)hideKeyboard{
    [self.floatLabledTextField resignFirstResponder];
}



-(UIButton *)selectButton{
    if (_selectButton == nil) {
        _selectButton = [[UIButton alloc]init];
        [_selectButton addTarget:self action:@selector(selectClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectButton;
}

#pragma mark --- 点击类型所需控件 懒加载
-(UILabel *)clickTitleLabel{
    
    if (_clickTitleLabel == nil) {
        _clickTitleLabel = [[UILabel alloc] init];
        _clickTitleLabel.font = [UIFont systemFontOfSize:FONT_SIZE_1];
        _clickTitleLabel.textColor = COLOR_TEXT_2;
        _clickTitleLabel.text = self.placeHolder;
    }
    return _clickTitleLabel;
    
}

-(void)setSeperateKeyString:(NSString *)seperateKeyString{
    
    super.seperateKeyString = seperateKeyString;
    _clickValue_CS_Page_TextView.seperateKeyString = seperateKeyString;
    
}

-(CS_Page_TextView *)clickValue_CS_Page_TextView{
    
    if (_clickValue_CS_Page_TextView == nil) {
        
        NSString *valueString = [self getFormatPlacePlaceHolder];
        
        _clickValue_CS_Page_TextView = [CS_Page_TextView page_textViewWithFont:[UIFont systemFontOfSize:FONT_SIZE_REM] textColor:COLOR_TEXT_3 content:NSLocalizedString(valueString, @"") textAlignment:NSTextAlignmentLeft];
        _clickValue_CS_Page_TextView.seperateKeyString = self.seperateKeyString;
    }
    return _clickValue_CS_Page_TextView;
    
}



@end
